package com.jxy.homepage.config.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitConfig
 *
 * @author Jxy
 * @date 2022/3/4
 * @Description Rabbit配置
 */
@Configuration
public class RabbitConfig {


    @Value("${spring.rabbitmq.my-exchange.topic_exchange}")
    public String topicExchange;

    @Value("${spring.rabbitmq.my-exchange.direct_exchange}")
    public String directExchange;

    @Value("${spring.rabbitmq.my-exchange.fanout_exchange}")
    public String fanoutExchange;

    @Value("${spring.rabbitmq.my-exchange.header_exchange}")
    public String headerExchange;


    /**
     * 简单队列
     */
    public static final String SIMPLE_QUEUE = "bbm.simple";
    /**
     * 处理对象的队列
     */
    public static final String OBJECT_QUEUE = "bbm.simple.object";

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(topicExchange);
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(directExchange);
    }

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(fanoutExchange);
    }

    @Bean
    public HeadersExchange headerExchange(){
        return new HeadersExchange(headerExchange);
    }
    @Bean
    public Queue simpleQueue() {
        return new Queue(SIMPLE_QUEUE);
    }
    @Bean
    public Queue objectQueue() {
        return new Queue(OBJECT_QUEUE);
    }

    @Bean
    public Binding topicCoreBind() {
        // bbm开头的routingKey 都路由到 bbm.simple 队列
        return BindingBuilder.bind(simpleQueue()).to(topicExchange()).with("bbm.#");
    }
    @Bean
    public Binding topicCoreBind1() {
        // bbm开头的routingKey 都路由到 bbm.simple 队列
        return BindingBuilder.bind(objectQueue()).to(topicExchange()).with("bbm.object.#");
    }

}
